import Worker from './absurdSql.worker.js'

import { initBackend } from 'absurd-sql/dist/indexeddb-main-thread'

let worker = null

function init() {
  worker = new Worker()
  // This is only required because Safari doesn't support nested
  // workers. This installs a handler that will proxy creating web
  // workers through the main thread
  initBackend(worker)
}

init()

export default class DaxieAdaptor {
  init() {
    // clear all
  }

  query({ timestamp }) {
    // worker.postMessage({
    //   type: 'QUERY_ONE',
    //   data: timestamp
    // })

    return null
  }

  insert({ timestamp, data }) {
    worker.postMessage({
      type: 'SCHEDULE_INSERT',
      data: {
        timestamp,
        data
      }
    })
  }
}
